// pages/paySuccess/paySuccess.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    payResult: 1,
    productGroupId: 2,
    payOrderId: '',
    showGiftBox: 0,
    shareCode: '',
    topicId: 'TOP-259272-E52844' // 获取下单的topicId,传给熟年生活列表用来判断是否是从熟年生活过来的
  },
  onShareAppMessage (options) {
    let href = app.globalData.frontUrl + 'coupon_order?shareCode=' + this.data.shareCode
    console.log(href)
    return {
      title: '送你一个大红包，赶快拆开看看吧',
      path: '/pages/middlewave/middlewave?href=' + encodeURIComponent(href),
      imageUrl: '/img/sharebag.png',
      success: function (shareTickets) {
        console.log(shareTickets)
      },
      fail: function () {
        
      },
      complete: function () {

      }
    }
  },
  backToDiscoverlist () {
    let storageTopicid = wx.getStorageSync('selectedTopicId')
    if (storageTopicid === this.topicId){
      // 如果是从发现生活列表过来的专题
      wx.navigateTo({
        url: '/pages/discoverList/discoverList?isShare=1&showIcon=1',
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
      })
    }
    else {
      wx.navigateTo({
        url: '/pages/discoverList/discoverList',
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
      })
    }
  },
  backToOrder (event) {
    let current = event.currentTarget.dataset
    let href = current.href
    if (href == 'order') {
      let url = app.globalData.frontUrl + 'myOrder?type=' + this.data.productGroupId
      wx.navigateTo({
        url: '/pages/middlewave/middlewave?href=' + encodeURIComponent(url),
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
      })
    } else {
      wx.navigateTo({
        url: '/pages/index/index',
        success: function(res) {},
        fail: function(res) {},
        complete: function(res) {},
      })
    }
    
  },
  longpress() {
    // 长按识别二维码
    wx.previewImage({
      urls: ['/static/img/qr_ylh.png'],
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    console.log(decodeURIComponent(options.shareCode))
    this.topicId = options.topicId
    this.setData({
      payResult: options.payResult,
      productGroupId: options.productGroupId,
      payOrderId: options.payOrderId,
      shareCode: options.shareCode
    })
    if (this.data.shareCode) {
      this.setData({
        showGiftBox: 1
      })
    }
    else {
      this.setData({
        showGiftBox: 2
      })
    }
    // 隐藏分享
    wx.hideShareMenu({
      success: () => {
        console.log('hideShareMenu')
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  }
})